<template>
  <div>
    <el-table :data="tableData">
      <el-table-column prop="action.id" label="订单序号"></el-table-column>
      <el-table-column prop="action.buyTime" label="下单时间" :formatter="formatData"></el-table-column>
      <el-table-column prop="action.result" label="订单状态">
        <template  #default="scope">
            {{scope.row.action.result == '0' ? "交易失败" : scope.row.action.result == '1' ? "交易成功": 
            scope.row.action.result == '2' ? "等待确认" :scope.row.action.result == '5' ? "已发货" :''}}
          </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
        <el-button @click="ConfirmOrder(scope.data)">下一步</el-button>
        <el-button @click="CancleOrder(scope.row)">取消</el-button>
      </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "OrderHistory",
  data(){
    return{
      tableData:[
      ],
      readorder:false,
      action: {},
      goods: {},
      user: {}

    }
  },

  methods:{
    formatData(row, column, cellValue, index){
		
		//把传过来的日期进行回炉重造一下，又创建了一个js的 Date对象，进行重新构造，转为String字符串
		//最终返回 s 就可以了
		var s =	new Date(cellValue).toLocaleString();
	return s;
 },
    ConfirmOrder(data){
      request.get("http://localhost:8086/seller/prepareFineWaitingforSendOut?tradeid="+data.action.id).then(res => {
        if (res.flag) {
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
      })
    },
    CancleOrder(row){
      request.get("http://localhost:8086/seller/CancelTrad?id="+row.action.id+"&goodsid="+row.action.goodsId).then(res => {
        if (res.flag) {
            this.$message({
              type: 'success',
              message: res.msg
            })
          }
          else {
            this.$message.error(res.msg);
          }
      })
    },
    getOrders() {
      request.get("http://localhost:8087/order/viewOrders").then(res => {
        if (res.flag) {
          this.tableData = res.data['order2s']
          this.user = res.data['user']
          this.$message({
            type: 'success',
            message: res.msg
          });
        } else {
          this.$message.error(res.msg);
        }
      })
    },
    Showorder(data){
      this.action = data.action
      this.goods = data.goods
      this.readorder=true;
    },
    close1() {
      this.readorder = false;
    },
  },
  created() {
    this.getOrders()
  }
}
</script>

<style scoped>
.div2{
  background-size: 100% ;
  float: left;
  margin-top: -200px;
}
.b3{
  margin-bottom: 20px;
}
.dialog1{
  z-index: 2;
}
</style>
